package com.autonavi.yunda.yunji.core.enums;

import com.autonavi.yunda.yunji.common.exception.AmapException;
import com.autonavi.yunda.yunji.common.exception.AmapExceptionCode;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author cizhong.wcs
 * @date 2022/6/2 19:14
 */
public enum ParamType {

    STRING("string", String.class),
    INT("int", Integer.class),
    LONG("long", Long.class),
    DOUBLE("double", Double.class),
    FLOAT("float", Float.class),
    BOOLEAN("boolean", Boolean.class),
    OBJECT("object", Object.class),
    FILE("file", String.class),
    ARRAY("array", List.class);
    static final Map<String, ParamType> codeTypeMap = Arrays.stream(ParamType.values()).collect(Collectors.toMap(ParamType::getCode, t -> t));


    public static ParamType fromCode(String code) {
        ParamType paramType = codeTypeMap.get(code);
        if (paramType == null) {
            throw new AmapException(AmapExceptionCode.COMMON_ILLEGAL_PARAM, "not support this paramType code: " + code);
        }
        return paramType;
    }

    ParamType(String code, Class<?> type) {
        this.code = code;
        this.type = type;
    }

    @Getter
    private final Class<?> type;

    @Getter
    private final String code;


}
